package com.ruoyi.project.digital.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.digital.domain.UserPet;
import com.ruoyi.project.digital.service.IUserPetService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户与宠物关系Controller
 * 
 * @author ruoyi
 * @date 2023-10-30
 */
@RestController
@RequestMapping("/digital/petuser")
public class UserPetController extends BaseController
{
    @Autowired
    private IUserPetService userPetService;

    /**
     * 查询用户与宠物关系列表
     */
    @PreAuthorize("@ss.hasPermi('digital:petuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserPet userPet)
    {
        startPage();
        List<UserPet> list = userPetService.selectUserPetList(userPet);
        return getDataTable(list);
    }

    /**
     * 导出用户与宠物关系列表
     */
    @PreAuthorize("@ss.hasPermi('digital:petuser:export')")
    @Log(title = "用户与宠物关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserPet userPet)
    {
        List<UserPet> list = userPetService.selectUserPetList(userPet);
        ExcelUtil<UserPet> util = new ExcelUtil<UserPet>(UserPet.class);
        return util.exportExcel(list, "petuser");
    }

    /**
     * 获取用户与宠物关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('digital:petuser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userPetService.selectUserPetById(id));
    }

    /**
     * 新增用户与宠物关系
     */
    @PreAuthorize("@ss.hasPermi('digital:petuser:add')")
    @Log(title = "用户与宠物关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserPet userPet)
    {
        return toAjax(userPetService.insertUserPet(userPet));
    }

    /**
     * 修改用户与宠物关系
     */
    @PreAuthorize("@ss.hasPermi('digital:petuser:edit')")
    @Log(title = "用户与宠物关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserPet userPet)
    {
        return toAjax(userPetService.updateUserPet(userPet));
    }

    /**
     * 删除用户与宠物关系
     */
    @PreAuthorize("@ss.hasPermi('digital:petuser:remove')")
    @Log(title = "用户与宠物关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userPetService.deleteUserPetByIds(ids));
    }
}
